function sayHello() {
    // alert("Hello, JavaScript!");
    // 在大多数情况下，用户更喜欢对其操作的响应出现在网页中
    var paragraph = document.getElementById("result");
    paragraph.innerHTML = "Hello, JavaScript!";
}

function compute() {
    // 使用alert测试脚本是否被载入
    alert("Is the browser even loading my script?");
    var input1 = document.getElementById("num1");
    var input2 = document.getElementById("num2");
    var answer = document.getElementById("answer");
    answer.innerHTML = input1.value * input2.value;
}

function add() {
    // 加法器
    var input1 = document.getElementById("add1");
    var input2 = document.getElementById("add2");
    var answer = document.getElementById("add_answer");
    answer.innerHTML = parseFloat(input1.value) + parseFloat(input2.value);
}

function convertName() {
    // 名字转换器 输入Tom Smith，输出 SMITH, T.
    var name = document.getElementById("name").value;
    var firstName = name.substring(0, name.indexOf(" "));
    var lastName = name.substring(name.indexOf(" ") + 1).toUpperCase();
    var firstInitial = firstName.charAt(0);
    var result = document.getElementById("covert_result");
    result.innerHTML = lastName + ", " + firstInitial + ".";
}

function factorializer() {
    // 计算阶乘
    var num = document.getElementById("num").value;
    var result = 1;
    for (var i = 1; i <= num; i++) {
        result *= i;
    }
    var answer = document.getElementById("factor");
    answer.innerHTML = result;
}